package com.yld.car.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.yld.car.market.R;

public class CornerListView extends ListView {
	public CornerListView(Context paramContext) {
		super(paramContext);
	}

	public CornerListView(Context paramContext, AttributeSet paramAttributeSet) {
		super(paramContext, paramAttributeSet);
	}

	public CornerListView(Context paramContext, AttributeSet paramAttributeSet,
			int paramInt) {
		super(paramContext, paramAttributeSet, paramInt);
	}

	public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent) {
		switch (paramMotionEvent.getAction()) {

		case MotionEvent.ACTION_DOWN:
			if (pointToPosition((int) paramMotionEvent.getX(),
					(int) paramMotionEvent.getY()) == -1)

				setSelector(R.drawable.app_list_corner_shape);
		}

		return super.onInterceptTouchEvent(paramMotionEvent);

	}

	public void onMeasure(int paramInt1, int paramInt2) {
		super.onMeasure(paramInt1,
				View.MeasureSpec.makeMeasureSpec(536870911, -2147483648));
	}

	public void setListViewHeightBasedOnChildren(ListView paramListView) {
		ListAdapter localListAdapter = paramListView.getAdapter();
		if (localListAdapter == null)
			return;
		int i = 0;
		for (int j = 0;; j++) {
			if (j >= localListAdapter.getCount()) {
				ViewGroup.LayoutParams localLayoutParams = paramListView
						.getLayoutParams();
				localLayoutParams.height = (i + paramListView
						.getDividerHeight()
						* (-1 + localListAdapter.getCount()));
				paramListView.setLayoutParams(localLayoutParams);
				return;
			}
			View localView = localListAdapter.getView(j, null, paramListView);
			localView.measure(0, 0);
			i += localView.getMeasuredHeight();
		}
	}
}
